<?php
/**
 * User: tridungpham
 * Date: 6/23/11
 * Time: 4:40 PM
 */
 
class Module extends MVCBase
{
    protected $_name;
    protected $_tpl_path;
    protected $_data = array();

    function __construct()
    {
        
    }

    function setTemplate($strPath)
    {
        $path = APP_PATH . 'modules' . DS . $this->_name . DS . $strPath;
        if(!file_exists($path))
        {
            echo $path;
            exit('Module ' . $this->_name . ' cannot be found');
        }
        else
            $this->_tpl_path =& $path;
    }

    function setData($key,$value)
    {
        $this->_data[$key] = $value;
    }

    function setName($str)
    {
        $this->_name =& $str;
    }

    function render()
    {
        foreach($this->_data as $key => $value)
        {
            $$key = $value;
        }
        ob_start();
        require $this->_tpl_path;
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }
}